package com.quik.web.action;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.ModelAndView;

import com.quik.common.Constants;
import com.quik.entity.SysAccount;
import com.quik.exception.ErrorCode;
import com.quik.web.action.vo.JsonErrorResult;
import com.quik.web.action.vo.JsonResultItf;

public class BaseAction {

	public SysAccount getLoginAccount(HttpServletRequest request) {
		Object account = request.getSession().getAttribute(
				Constants.SESSION_ACCOUNT);
		if (account == null)
			throw new RuntimeException(ErrorCode.ERROR_NOLOGIN);
		return (SysAccount) account;
	}

	public JsonResultItf processJsonOnException(Exception e) {
		JsonErrorResult rs = new JsonErrorResult(e);
		return rs;
	}
	public ModelAndView processModelAndViewOnException(Exception e) {
		String error_info="";
		if(ErrorCode.ERROR_NOLOGIN.equals(e.getMessage())){
			error_info = "尚未登录系统，或者超时。请重新登录.";
		}else{
			error_info = e.getMessage();
		}
		return new ModelAndView("redirect:/portal/login").addObject("error_info", error_info);
	}
}
